home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1560 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  51 lines

  1. Path: thor.tu.hac.com!collins
  2. From: collins@thor.tu.hac.com (Ron Collins)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Strcat Doesn't work for this?
  5. Date: 15 Jan 1996 13:58:34 GMT
  6. Organization: Advanced Depot Systems
  7. Message-ID: <4ddmia$a1j@hacgate2.hac.com>
  8. References: <Pine.SOL.3.91.960111151925.25068C-100000@lore.cs.purdue.edu>
  9. NNTP-Posting-Host: thor.tu.hac.com
  10.  
  11. ** Craig Cook ** (cookca@cs.purdue.edu) wrote:
  12. : Here is my excerpt of code in question:
  13.  
  14.  
  15. : Putword(int w, char *imageChar)
  16. : {
  17. :         w = (w & 0xff);
  18. :         strcat( imageChar, (const char *)w );
  19.  
  20. : }
  21.  
  22. : Why does it core dump?  It should work right?
  23.  
  24. : Craig                                 
  25. :                               ,,,
  26.  
  27.  
  28. Forget all this tricky stuff.  The cast on "w" is wrong, and depends upon
  29. the "endianess" of your machine.  Just do it the simple way:
  30.  
  31.  
  32. void  Putword(int w, char *imageChar) {
  33. unsigned char temp[2];
  34.  
  35.     temp[0] = (char) w;
  36.     temp[1] = 0;
  37.  
  38.     strcat(imageChar, temp);
  39. }
  40.  
  41.  
  42.  
  43.                         -- Collins --
  44.                         
  45. -----
  46. The views expressed here are mine alone.
  47.  
  48. Ron Collins/Hughes Aircraft Company/M20,P20/Tucson Az 85706
  49. rcollins@thor.tu.hac.com    collins@seagull.rtd.com
  50. ยก----
  51.